<?php
/**
 *@file apppush.php
 *@author Zhe.Zhou(zhouzhe@haibao.com)
 *@date 2015-8-6 下午8:29:05
 *@brief  
 */
namespace haibao\app\business;

use haibao\app\data\AppPush as AppPushData;

class AppPush extends Base{
	public static function getAppList($filter){
		$appPushData = new AppPushData();
		return $appPushData->getAll($filter);
	}	
	public static function addApp($model){
		$appPushData = new AppPushData();
		$appPushData->add($model);
	}
	
	public static function updateApp($id,$arrSet){
		$appPushData = new AppPushData();
		$appPushData->updateById($id, $arrSet);
	}
	
	public function getOneById($appId){
		$appPushData = new AppPushData();
		return $appPushData->getOneById($appId);
	}
	
	public static function updateById($id,$arrSet){
		$appPushData = new AppPushData();
		$appPushData->updateById($id, $arrSet);
	}
	
	public static function getPowerList(){
		$appPushData = new AppPushData();
		return $appPushData->getPowerList();
	}
	
	public static function changeVersion($id,$status){
		$appPushData = new AppPushData();
		$appPushData->changeVersion($id,$status);
	}
	
	public static function addVersion($arrSet){
		$appPushData = new AppPushData();
		$appPushData->addAppPower($arrSet);
	}
	
	public static function setAppClickNum($id){
		if(empty($id)){
			throw new BusinessException('参数不正确',\haibao\app\business\Oauth::DATA_ERROR_CODE_EMPTY);
		}
		$appPushData = new AppPushData();
		$appPushData->setAppClickNum($id);
	}
	
	/**
	 * 根据版本判断是否需要显示应用推荐
	 */
	public static function isShowPushByVersion($version){
		if(!$version){
			throw new BusinessException('参数不正确',\haibao\app\business\Oauth::DATA_ERROR_CODE_EMPTY);
		}
	    $appPushData = new AppPushData();
	    $appPowerList = $appPushData->getClosePoswerList();
	    $result = 1;
	    if(!empty($appPowerList)){
	        foreach($appPowerList as $list){
	        	if($version == $list){
	        		$result = 0;
	        		break;
	        	}
	        }
	    }
	    
	    return $result;
	}
}